<!--
 * @Descripttion: 证书
 * @version: 
 * @Author: Bruce
 * @Date: 2020-11-02 14:26:30
 * @LastEditors: Bruce
 * @LastEditTime: 2020-11-05 17:15:39
-->


<template>
	<div class="container tableFlex">
		<my-table :tableTitle="tableTitle" :tableData="tableData" :loading="loading">
			<template v-slot:action="{ row }">
				
				<el-button v-if="row.state === '已出准考证'" type="text" size="small" @click="zkz(row)">下载准考证</el-button>
				<el-button v-if="row.state === '已出证书'" type="text" size="small" @click="zs(row)">下载证书</el-button>
			</template>
		</my-table>
		<page :currentPage.sync="currentPage" :total="total" :pageSize="size"></page>
	</div>
</template>

<script>
	import {
		list
	} from "@/api/apiList/user.js"
	
	import {BASE_URL} from "@/utils/common.js"

	export default {
		name: "certificate",
		data() {
			return {
				currentPage: 1, //当前页数
				total: 0, //总数
				size: 10, //每页条数
				loading: false,
				tableTitle: [{
						label: '考试名称',
						prop: 'ename'
					},
					{
						label: '证书名称',
						prop: 'eccnm'
					},
					{
						label: '证书时间',
						prop: 'qftm'
					},
					{
						label: '状态',
						prop: 'state' //1-待审核、2-审核通过、3-审核不通过、4-已缴费、5-已出准考证、6-已出证书
					}
				],
				tableData: [] //表格数据
			}
		},
		watch: {
			currentPage: {
				async handler(currentPage) {
					this.loading = true
					let res = await this.API_list(currentPage, this.size)
					console.log(res)
					let {
						current,
						records
					} = res.data.data
					this.currentPage = current
					this.total = records.length
					this.tableData = this.stateFilter(records)
					this.loading = false
				},
				immediate: true
			}
		},
		methods: {
			async API_list(current, size) {
				let result = {
					page: {
						current, //第几页
						size //每页条数
					}
				}
				return await list(result)
			},
			goDetails(row) { //查看详细
				console.log(row)
			},
			zkz(row) {//打印准考证
				window.location.href = BASE_URL + row.admission
			},
			zs(row) {//打印证书
				// console.log(row.qualification)
				window.location.href = BASE_URL + row.qualification
			},
			stateFilter(arr) { //过滤状态
				return arr.map((item) => {
					let obj = {}
					if (item.state === 1) {
						item.state = "待审核"
						obj = item
					} else if (item.state === 2) {
						item.state = "审核通过"
						obj = item
					} else if (item.state === 3) {
						item.state = "审核不通过"
						obj = item
					} else if (item.state === 4) {
						item.state = "已缴费"
						obj = item
					} else if (item.state === 5) {
						item.state = "已出准考证"
						obj = item
					}else if (item.state === 6) {
						item.state = "已出证书"
						obj = item
					}
					return obj
				})
			}
		},
		async activated() { //激活状态
			this.loading = true
			let res = await this.API_list(this.currentPage, this.size)

			let {
				current,
				records
			} = res.data.data
			this.currentPage = current
			this.total = records.length
			this.tableData = this.stateFilter(records)
			this.loading = false
		}
	}
</script>

<style>
</style>
